﻿
CREATE PROCEDURE [dbo].[proc_Order_Change_ProjectItem_GetList]
	(
		@CId int,
		@OId uniqueidentifier
	)
AS
	Select
	p.Id,
	p.ProjectId,
	p.OrderId As OId,
	p.ProductId,
	p.CostPrice,
	p.SalePrice,
	p.Description,
	p.TypeId,
	p.IsFinish,
	p.SupplierId,
	p.CompanyId,
	p.CreateUser,
	p.Salesman,
	p.SalesmanAccount,
	p.ProductName,
	p.TypeName,
	p.SupplierName,
	IsNull(p.CreateDate,p.UpTime) as CreateDate,
	IsNull(p.FinishDate,'1910/01/01') as FinishDate,
	p.ExecPerson,
	p.FinanceAudit,
	0 As Change
	From Project p Where OrderId=@OId
Union All
	Select
	p2.Id,
	'2725df9f-2c69-4b7e-a867-acc57a262384' As ProjectId,
	p2.OId,
	p2.ProductId,
	p2.CostPrice,
	p2.SalePrice,
	p2.Description,
	p2.TypeId,
	p2.IsFinish,
	p2.SupplierId,
	p2.CompanyId,
	p2.CreateUser,
	p2.Salesman,
	p2.SalesmanAccount,
	p2.ProductName,
	p2.TypeName,
	p2.SupplierName,
	IsNull(p2.CreateDate,p2.UpTime) as CreateDate,
	IsNull(p2.FinishDate,'1910/01/01') as FinishDate,
	p2.ExecPerson,
	p2.FinanceAudit,
	1 As Change
	From Order_Change_Project p2 Where CId=@CId And OId=@OId
Order By SupplierId,ProductId,Change
	RETURN
